﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<html>
    <head>
        <script type="text/javascript">
            function editSP() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    location.href = "/SitePage/Edit/?id=" + row.SitePageId + "";
                }
                else {
                    $.messager.alert("Message", "Please select one record.");
                }
            }
            function removeSP() {
                var row = $('#dg').datagrid('getSelected');
                if (row) {
                    $.messager.confirm('Confirm', 'Are you sure you want to remove this Site Page?', function (r) {
                        if (r) {
                            $.post('/SitePage/DeleteSP', { id: row.SitePageId }, function (result) {
                                if (result == "success") {
                                    $.messager.alert("Message", "Delete Successfully");
                                    $('#dg').datagrid('reload');
                                } else {
                                    $.messager.show({    // show error message
                                        title: 'Error',
                                        msg: 'Please contact the admin for support'
                                    });
                                }
                            }, 'text');
                        }
                    });
                }
                else {
                    $.messager.alert("Message", "Please select one record.");
                }
            }
        </script>
    </head>
    <body>
        <table id="dg" title="Site Page" class="easyui-datagrid" style="height:500px"
                url="/SitePage/GetAllPages"
                toolbar="#toolbar" pagination="true" iconCls="icon-ok"
                rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                <tr>
                    <th field="SitePageId" width="50" hidden="true">SitePageId</th>
                    <th field="SitePageTitle" width="50">Page Title</th>
                    <th field="CreateDate" width="50" formatter="ToJavaScriptDate">Create Date</th>
                    <th field="CreateUser" width="50">Create User</th>
                </tr>
            </thead>
        </table>
        <div id="toolbar">
            <a href="/SitePage/Create" class="easyui-linkbutton" iconcls="icon-add" plain="true" >New Page</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editSP()">Edit Page</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="removeSP()">Remove Page</a>
        </div>
    </body>
</html>